# Maintainer : Christian Rebischke <Chris.Rebischke[at]archlinux[dot]org>
# Contributor: Daniel Wallace <danielwallace at gtmanfred dot com>
# Contributor: Lucas De Marchi <lucas.de.marchi@gmail.com>

pkgname=connman
pkgver=1.41
pkgrel=1
pkgdesc="Intel's modular network connection manager"
url="https://01.org/connman"
arch=('loong64' 'x86_64')
license=('GPL2')
makedepends=('bluez' 'wpa_supplicant' 'openconnect' 'openvpn' 'ppp' 'iwd')
depends=('dbus' 'iptables' 'gnutls' 'glib2')
backup=('etc/connman/main.conf')
optdepends=('bluez: Support for Bluetooth devices'
            'wpa_supplicant: for WiFi devices'
            'pptpclient: for ppp support'
            'openvpn: for VPN Support'
            'iwd: for WiFi devices')
source=("${pkgname}-${pkgver}.tar.xz::https://www.kernel.org/pub/linux/network/${pkgname}/${pkgname}-${pkgver}.tar.xz"
        "${pkgname}-${pkgver}.tar.sign::https://www.kernel.org/pub/linux/network/${pkgname}/${pkgname}-${pkgver}.tar.sign"
        'allow_group_network.diff')
sha512sums=('b7880d908635ab9350c12e207213d20b11c1a50afcb93ae92e1fc57d4345bf792afe1a5534650e18b8cd05a3766ce9993083b2d659e49f87b867e6f2c1a83b2d'
            'SKIP'
            '06dd5867d460f1c3cf6c359e650ca2ef24495493a99cd03dbd17f23e587e9066d9bc98758d85d5c690d1ae21fa77ad8da5e2fa83d0b52c95d7a535784c5c4964')
validpgpkeys=('E932D120BC2AEC444E558F0106CA9F5D1DCF2659')

prepare(){
  cd "${pkgname}-${pkgver}"
  patch -Np1 -i "${srcdir}/allow_group_network.diff"
}

build() {
  cd "${pkgname}-${pkgver}"

  ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var \
      --bindir=/usr/bin \
      --sbindir=/usr/bin \
      --with-systemdunitdir=/usr/lib/systemd/system \
      --enable-pptp \
      --enable-openconnect \
      --enable-vpnc \
      --enable-openvpn \
      --enable-polkit \
      --enable-client \
      --enable-nmcompat \
      --enable-test \
      --enable-pie \
      --enable-iwd
  make
}

package() {
  make -C "${pkgname}-${pkgver}" DESTDIR="${pkgdir}" install
  install -Dm755 "${srcdir}/${pkgname}-${pkgver}/client/${pkgname}ctl" "${pkgdir}/usr/bin/${pkgname}ctl"
  install -Dm644 "${srcdir}/${pkgname}-${pkgver}/src/main.conf" "${pkgdir}/etc/connman/main.conf"
  find "${pkgdir}/usr" -name \*.service -exec sed -i 's/s\(bin\)/\1/' {} +
# See FS#48044
  sed -i 's/ProtectSystem=full/ProtectSystem=true/' "${pkgdir}"/usr/lib/systemd/system/connman.service
  rm -r "${pkgdir}"/usr/lib/tmpfiles.d
}
